package com.example.controller;

import com.example.MyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/Yml")
public class YmlController {


    @Value("${xzz}")
    private String yml_value;
    @Value("${user.name}")
    private String name;
    @Value("${user.age}")
    private String age;
    @Value("${list[1]}")
    private String list;
    @Value("${tempPath}")
    private String temp;

    // 使用自动装配 读取所有的yml文件中的数据
    @Autowired
    private Environment env;

    @Autowired
    private MyDataSource dataSource;


    @RequestMapping("/value")
    public String get_yml_value() {
        System.out.println(yml_value);
        System.out.println(name);
        System.out.println(age);
        System.out.println(list);
        System.out.println(temp);
        System.out.println("----------------------------");
        System.out.println(env.getProperty("tempPath"));
        System.out.println("---------------------------");
        System.out.println(dataSource.getUsername());
        return "springboot running....";
    }
}
